"""
基础常量定义模块
==============

定义整个项目中使用的常量，不依赖其他内部模块。
"""

from enum import Enum
from typing import Dict, List


# 服务类型常量
class SERVICE_TYPES:
    """服务类型常量"""
    API_GATEWAY = "api_gateway"
    AUTH_SERVICE = "auth_service"
    USER_SERVICE = "user_service"
    TRADING_SERVICE = "trading_service"
    MARKET_DATA_SERVICE = "market_data_service"
    STRATEGY_SERVICE = "strategy_service"
    NOTIFICATION_SERVICE = "notification_service"
    MONITORING_SERVICE = "monitoring_service"
    
    ALL = [
        API_GATEWAY, AUTH_SERVICE, USER_SERVICE, TRADING_SERVICE,
        MARKET_DATA_SERVICE, STRATEGY_SERVICE, NOTIFICATION_SERVICE, 
        MONITORING_SERVICE
    ]


# 环境常量
class ENVIRONMENTS:
    """环境常量"""
    DEVELOPMENT = "development"
    TESTING = "testing"
    STAGING = "staging"
    PRODUCTION = "production"
    
    ALL = [DEVELOPMENT, TESTING, STAGING, PRODUCTION]


# 日志级别常量
class LOG_LEVELS:
    """日志级别常量"""
    DEBUG = "DEBUG"
    INFO = "INFO"
    WARNING = "WARNING"
    ERROR = "ERROR"
    CRITICAL = "CRITICAL"
    
    ALL = [DEBUG, INFO, WARNING, ERROR, CRITICAL]


# 数据库类型常量
class DATABASE_TYPES:
    """数据库类型常量"""
    POSTGRESQL = "postgresql"
    MYSQL = "mysql"
    MONGODB = "mongodb"
    REDIS = "redis"
    INFLUXDB = "influxdb"
    
    ALL = [POSTGRESQL, MYSQL, MONGODB, REDIS, INFLUXDB]


# HTTP状态码常量
class HTTP_STATUS:
    """HTTP状态码常量"""
    OK = 200
    CREATED = 201
    NO_CONTENT = 204
    BAD_REQUEST = 400
    UNAUTHORIZED = 401
    FORBIDDEN = 403
    NOT_FOUND = 404
    METHOD_NOT_ALLOWED = 405
    CONFLICT = 409
    UNPROCESSABLE_ENTITY = 422
    INTERNAL_SERVER_ERROR = 500
    BAD_GATEWAY = 502
    SERVICE_UNAVAILABLE = 503


# 缓存键前缀
class CACHE_KEYS:
    """缓存键前缀常量"""
    USER_PREFIX = "user:"
    AUTH_PREFIX = "auth:"
    SESSION_PREFIX = "session:"
    TOKEN_PREFIX = "token:"
    MARKET_DATA_PREFIX = "market:"
    TRADING_PREFIX = "trading:"
    STRATEGY_PREFIX = "strategy:"


# 消息队列主题
class QUEUE_TOPICS:
    """消息队列主题常量"""
    USER_EVENTS = "user.events"
    AUTH_EVENTS = "auth.events"
    TRADING_EVENTS = "trading.events"
    MARKET_DATA_EVENTS = "market.events"
    STRATEGY_EVENTS = "strategy.events"
    NOTIFICATION_EVENTS = "notification.events"


# 默认配置值
class DEFAULT_VALUES:
    """默认配置值常量"""
    SERVICE_VERSION = "1.0.0"
    SERVICE_HOST = "0.0.0.0"
    SERVICE_PORT = 8000
    LOG_LEVEL = "INFO"
    LOG_FORMAT = "detailed"
    LOG_DIRECTORY = "./logs"
    ENVIRONMENT = "development"
    DEBUG = False
    
    # 数据库连接
    DB_POOL_SIZE = 10
    DB_MAX_OVERFLOW = 20
    DB_POOL_TIMEOUT = 30
    DB_POOL_RECYCLE = 3600
    
    # Redis连接
    REDIS_POOL_SIZE = 10
    REDIS_TIMEOUT = 5
    
    # JWT配置
    JWT_ALGORITHM = "HS256"
    JWT_ACCESS_TOKEN_EXPIRE_MINUTES = 30
    JWT_REFRESH_TOKEN_EXPIRE_DAYS = 7
    
    # 监控配置
    METRICS_PATH = "/metrics"
    HEALTH_CHECK_PATH = "/health"
    
    # 文件上传
    MAX_FILE_SIZE = "10MB"
    UPLOAD_PATH = "./uploads"


# 正则表达式模式
class REGEX_PATTERNS:
    """正则表达式模式常量"""
    EMAIL = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
    PHONE = r'^\+?1?\d{9,15}$'
    PASSWORD = r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$'
    UUID = r'^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'
    SLUG = r'^[a-z0-9]+(?:-[a-z0-9]+)*$'


# 时间格式
class TIME_FORMATS:
    """时间格式常量"""
    ISO_8601 = "%Y-%m-%dT%H:%M:%S.%fZ"
    DATE_ONLY = "%Y-%m-%d"
    TIME_ONLY = "%H:%M:%S"
    DATETIME = "%Y-%m-%d %H:%M:%S"
    FILENAME = "%Y%m%d_%H%M%S"


# API版本
class API_VERSIONS:
    """API版本常量"""
    V1 = "v1"
    V2 = "v2"
    CURRENT = V1


# 权限常量
class PERMISSIONS:
    """权限常量"""
    READ = "read"
    WRITE = "write"
    DELETE = "delete"
    ADMIN = "admin"
    
    ALL = [READ, WRITE, DELETE, ADMIN]


# 角色常量
class ROLES:
    """角色常量"""
    USER = "user"
    MODERATOR = "moderator"
    ADMIN = "admin"
    SUPER_ADMIN = "super_admin"
    
    ALL = [USER, MODERATOR, ADMIN, SUPER_ADMIN]


# 事件类型
class EVENT_TYPES:
    """事件类型常量"""
    USER_CREATED = "user.created"
    USER_UPDATED = "user.updated"
    USER_DELETED = "user.deleted"
    USER_LOGIN = "user.login"
    USER_LOGOUT = "user.logout"
    
    TRADE_CREATED = "trade.created"
    TRADE_EXECUTED = "trade.executed"
    TRADE_CANCELLED = "trade.cancelled"
    
    STRATEGY_STARTED = "strategy.started"
    STRATEGY_STOPPED = "strategy.stopped"
    STRATEGY_ERROR = "strategy.error"


# 文件类型
class FILE_TYPES:
    """文件类型常量"""
    IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp']
    DOCUMENT_EXTENSIONS = ['.pdf', '.doc', '.docx', '.txt', '.rtf']
    SPREADSHEET_EXTENSIONS = ['.xls', '.xlsx', '.csv']
    ARCHIVE_EXTENSIONS = ['.zip', '.rar', '.7z', '.tar', '.gz']
    
    ALLOWED_EXTENSIONS = IMAGE_EXTENSIONS + DOCUMENT_EXTENSIONS + SPREADSHEET_EXTENSIONS


# 导出所有常量
__all__ = [
    "SERVICE_TYPES",
    "ENVIRONMENTS", 
    "LOG_LEVELS",
    "DATABASE_TYPES",
    "HTTP_STATUS",
    "CACHE_KEYS",
    "QUEUE_TOPICS",
    "DEFAULT_VALUES",
    "REGEX_PATTERNS",
    "TIME_FORMATS",
    "API_VERSIONS",
    "PERMISSIONS",
    "ROLES",
    "EVENT_TYPES",
    "FILE_TYPES"
]
